package com.dbb.trade.entity.shipment;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;

import com.dbb.trade.entity.IdEntity;
/**
 * 某个集装箱
 * @author Administrator
 *
 */
@Entity
public class Shipment extends IdEntity {
	private String code;
	private Date loadingDate;
	private Date eTD;
	private String containerNo;
	private String agent;
	private String boatName;
	private List<Groups> groups;
	
	public Shipment() {
		super();
	}

	public Shipment(String code, Date loadingDate, Date eTD,
			String containerNo, String agent, String boatName,
			List<Groups> groups) {
		super();
		this.code = code;
		this.loadingDate = loadingDate;
		this.eTD = eTD;
		this.containerNo = containerNo;
		this.agent = agent;
		this.boatName = boatName;
		this.groups = groups;
		for(Groups g : groups) {
			if(g.getRealGroup() != null) {
				g = g.getRealGroup();
			}
			totalPrice += g.getTotalPrice();
			totalPairs += g.getTotalPairs();
			totalNw += g.getTotalNw();
			totalGw += g.getTotalGw();
			totalCbm += g.getTotalCbm();
			totalCtnNum += g.getCtnNum();
		}
	}
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Date getLoadingDate() {
		return loadingDate;
	}

	public void setLoadingDate(Date loadingDate) {
		this.loadingDate = loadingDate;
	}

	public Date getETD() {
		return eTD;
	}

	public void setETD(Date eTD) {
		this.eTD = eTD;
	}

	public String getContainerNo() {
		return containerNo;
	}

	public void setContainerNo(String containerNo) {
		this.containerNo = containerNo;
	}

	public String getAgent() {
		return agent;
	}

	public void setAgent(String agent) {
		this.agent = agent;
	}

	public String getBoatName() {
		return boatName;
	}

	public void setBoatName(String boatName) {
		this.boatName = boatName;
	}

	@OneToMany(mappedBy = "shipment", cascade = CascadeType.ALL)
	public List<Groups> getGroups() {
		return groups;
	}

	public void setGroups(List<Groups> groups) {
		this.groups = groups;
	}
	
	private Integer totalCtnNum = 0;
	private Float totalPrice = 0f;
	private Integer totalPairs = 0;
	private Float totalNw = 0f;
	private Float totalGw = 0f;
	private Float totalCbm = 0f;
	
	public void praseGroup() {
		for(Groups g : groups) {
			if(g.getRealGroup() != null) {
				g = g.getRealGroup();
			}
			totalPrice += g.getTotalPrice();
			totalPairs += g.getTotalPairs();
			totalNw += g.getTotalNw();
			totalGw += g.getTotalGw();
			totalCbm += g.getTotalCbm();
			totalCtnNum += g.getCtnNum();
		}
	}
	public Float getTotalPrice(){
		return totalPrice ;
	}
	
	public Integer getTotalPairs(){
		return totalPairs;
	}
	
	public Float getTotalNw(){
		return totalNw;
	}
	
	public Float getTotalGw(){
		return totalGw;
	}

	public Float getTotalCbm(){
		return totalCbm;
	}
	
	public Integer getTotalCtnNum(){
		return totalCtnNum;
	}

	public void setTotalCtnNum(Integer totalCtnNum) {
		this.totalCtnNum = totalCtnNum;
	}

	public void setTotalPrice(Float totalPrice) {
		this.totalPrice = totalPrice;
	}

	public void setTotalPairs(Integer totalPairs) {
		this.totalPairs = totalPairs;
	}

	public void setTotalNw(Float totalNw) {
		this.totalNw = totalNw;
	}

	public void setTotalGw(Float totalGw) {
		this.totalGw = totalGw;
	}

	public void setTotalCbm(Float totalCbm) {
		this.totalCbm = totalCbm;
	}

	@Override
	public String toString() {
		return "Shipment [code=" + code + ", loadingDate=" + loadingDate
				+ ", eTD=" + eTD + ", containerNo=" + containerNo + ", agent="
				+ agent + ", boatName=" + boatName
				+ ", totalCtnNum=" + totalCtnNum + ", totalPrice=" + totalPrice
				+ ", totalPairs=" + totalPairs + ", totalNw=" + totalNw
				+ ", totalGw=" + totalGw + ", totalCbm=" + totalCbm + "]";
	}
	
}
